package com.zjl.spring.common;

import com.zjl.spring.enums.BaseCode;
import com.zjl.spring.enums.BaseCodeI;

import java.io.Serializable;

/**
 * @Auther: zhuangjl
 * @Date: 2021/11/11 15:35
 */
public class Response implements Serializable {

    private static final long serialVersionUID = 1L;
    /**
     * true:成功  false:失败
     */
    private boolean status;
    /**
     * 提示信息
     */
    private String message;
    /**
     * 提示code
     */
    private String code;

    public Response() {
    }

    public static Response buildFailure(BaseCodeI baseCode) {
        Response response = new Response();
        response.setStatus(false);
        response.setCode(baseCode.getCode());
        response.setMessage(baseCode.getDesc());
        return response;
    }

    public static Response buildFailure(String baseCode, String msg) {
        Response response = new Response();
        response.setStatus(false);
        response.setCode(baseCode);
        response.setMessage(msg);
        return response;
    }

    public static Response buildSuccess() {
        Response response = new Response();
        response.setStatus(true);
        response.setCode(BaseCode.SUCCESS.getCode());
        response.setMessage(BaseCode.SUCCESS.getDesc());
        return response;
    }

    public boolean isStatus() {
        return status;
    }

    public void setStatus(boolean status) {
        this.status = status;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }
}
